package org.jeecg.glr.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.glr.entity.GlrLed;
import org.jeecg.glr.mapper.GlrLedMapper;
import org.jeecg.glr.service.IGlrLedService;
import org.jeecg.glr.service.IGlrLightPoleDeviceService;
import org.jeecg.glr.util.GLRConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description: LED屏管理
 * @Author: jeecg-boot
 * @Date:   2020-02-20
 * @Version: V1.0
 */
@Service
public class GlrLedServiceImpl extends ServiceImpl<GlrLedMapper, GlrLed> implements IGlrLedService {

    @Resource GlrLedMapper glrLedMapper;

    @Autowired
    private IGlrLightPoleDeviceService glrLightPoleDeviceService;

    @Override
    public List<GlrLed> getLedByIds(String str) {
        return glrLedMapper.getLedByIds(str);
    }

    @Override
    public void ledOpenOrClose(String id, String status) {
        GlrLed led = new GlrLed();
        led.setId(id);
        led.setOpenStatus(status);
        glrLedMapper.updateById(led);
    }

    @Override
    public void updateProgressByCommandId(String progress, String commandId) {
        glrLedMapper.updateProgressByCommandId(progress,commandId);
    }

    @Override
    public void updateBrightnessByCodes(Integer brightness, String code) {
        glrLedMapper.updateBrightnessByCode(brightness,code);
    }

    @Override
    public void saveEntity(GlrLed glrLed){
        glrLedMapper.insert(glrLed);
        glrLightPoleDeviceService.dataProecss(glrLed,GLRConstant.GLR_LIGHT_POLE_DEVICE_TYPE_ADD);
    }

    @Override
    public void updateEntityById(GlrLed glrLed){
        glrLightPoleDeviceService.dataProecss(glrLed,GLRConstant.GLR_LIGHT_POLE_DEVICE_TYPE_EDIT);
        glrLedMapper.updateById(glrLed);

    }

    @Override
    public void removeEntityById(String id){
        GlrLed glrLed=glrLedMapper.selectById(id);
        glrLedMapper.deleteById(id);
        glrLightPoleDeviceService.dataProecss(glrLed,GLRConstant.GLR_LIGHT_POLE_DEVICE_TYPE_DELETE);
    }

    @Override
    public void removeEntityByIds(List<String> asList){
        for(String stId:asList){
            GlrLed glrLed=glrLedMapper.selectById(stId);
            glrLedMapper.deleteById(stId);
            glrLightPoleDeviceService.dataProecss(glrLed,GLRConstant.GLR_LIGHT_POLE_DEVICE_TYPE_DELETE);
        }
    }

    @Override
    public List<String> getLedStatus() {
        String sql="select status from glr_led where 1=1";
       /* if(!SysUtil.getUserInfo().getUserType().equals(SysConstant.SYS_USER_TYPE_ADMIN)){
                sql=sql+" and sys_company_code='"+SysUtil.getUserInfo().getSysCompanyCode()+"'";
        }*/
        return glrLedMapper.getLedStatus(sql);
    }

    @Override
    public GlrLed getLedByCode(String code) {
        return glrLedMapper.getLedByCode(code);
    }
}
